<template>
  <el-cascader
    :options="options"
    :props="props"
    separator="-"
    :value="value"
    @change="changeID"
  />
</template>

<script>
import { getDepartmentApi } from '@/api/department'
import { transObjToTree } from '@/utils'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      options: [],
      props: {
        value: 'id',
        label: 'name'
      }
    }
  },
  created() {
    this.getDepartment()
  },
  methods: {
    async getDepartment() {
      this.options = transObjToTree(await getDepartmentApi(), 0)
    },
    changeID(e) {
      if (e.length) {
        this.$emit('input', e[e.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>

<style scoped lang="scss">

</style>
